package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqGeneralValueResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class SetPDOPThresholdValueReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,V4,PDOP,175506,10,175508,A,2250.2153,N,11391.6210,E,1.49,0,020621,FFFFDFFF
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String thresholdValue=split[5];//PDOP的门限值
        String time = split[6];//指令回复的时间（时分秒）
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqGeneralValueResult mqGeneralValueResult = new MqGeneralValueResult();
        mqGeneralValueResult.setCommandNumber(commandNumber);
        mqGeneralValueResult.setDeviceDate(date);
        mqGeneralValueResult.setDeviceStatus(deviceStatus);
        mqGeneralValueResult.setDeviceTime(time);
        mqGeneralValueResult.setValue(thresholdValue);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqGeneralValueResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().setPDOPResponse(mqGeneralValueResult);
        return imei;
    }
}
